#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>

void handler(int signo){
  printf("get a signal: %d, pid: %d\n", signo, getpid());
}

int main(){

  signal(SIGCHLD, handler);
  //signal(SIGCHLD, SIG_IGN);//显式设置忽略SIGCHLD信号，当进程退出后，自动释放僵尸进程

  pid_t id = fork();
  if(id == 0){
    int cnt = 5;
    while(cnt){
      printf("I am child: %d\n", getpid());
      sleep(1);
      cnt--;
    }
    exit(0);
  }
  while(1);
  return 0;
}
